package com.hlkj.baojin.controller;

import com.hlkj.baojin.entity.DutyLog;
import com.hlkj.baojin.entity.dto.DutyDto;
import com.hlkj.baojin.entity.dto.DutyLogSearchDto;
import com.hlkj.baojin.entity.dto.DutySearchDto;
import com.hlkj.baojin.service.IDutyService;
import com.hlkj.baojin.utils.ErrororUtil;
import com.hlkj.baojin.utils.ValidationUtil;
import com.hlkj.baojin.utils.bean.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author HULIN
 * @created with: baojin
 * @package com.hlkj.baojin.controller
 * @description:
 * @date 2019/1/29 13:26
 * @modified By:
 * @Copyright © 2018 HAILIANG Info. Tech Ltd. All rights reserved.
 */
@Api(value = "/bjjk", description = "值班管理")
@RestController
public class DutyController {

    @Autowired
    private IDutyService dutyService;

    @ApiOperation(value = "值班列表", tags = {"值班管理"})
    @ApiResponses(value = @ApiResponse(code = 200, message = "成功", response = DutyDto.class))
    @PostMapping(value = "/duty/list")
    public ResponseEntity<JsonResult> companyList(@RequestBody DutySearchDto dutySearchDto) {
        return ResponseEntity.ok(JsonResult.success(dutyService.findDuty(dutySearchDto)));
    }

    @ApiOperation(value = "值班保存", tags = {"值班管理"})
    @ApiResponses(value = @ApiResponse(code = 200, message = "成功", response = void.class))
    @PostMapping(value = "/duty/save")
    public ResponseEntity<JsonResult> companySave(@RequestBody DutyDto dutyDto) {
        ValidationUtil.validate(dutyDto);
        dutyService.saveDuty(dutyDto);
        return ResponseEntity.ok(JsonResult.success());
    }

    @ApiOperation(value = "值班更新", tags = {"值班管理"})
    @ApiResponses(value = @ApiResponse(code = 200, message = "成功", response = void.class))
    @PostMapping(value = "/duty/update")
    public ResponseEntity<JsonResult> companyUpdate(@RequestBody DutyDto dutyDto) {
        ErrororUtil.isFalseNull(dutyDto.getDutyStatus(), "更新值班", "不可更新状态");
        dutyService.updateDuty(dutyDto);
        return ResponseEntity.ok(JsonResult.success());
    }

    @ApiOperation(value = "值班删除-离职", tags = {"值班管理"})
    @ApiResponses(value = @ApiResponse(code = 200, message = "成功", response = void.class))
    @PostMapping(value = "/duty/delete/{dutyId}")
    public ResponseEntity<JsonResult> companyDelete(@PathVariable("dutyId") String dutyId) {
        dutyService.deleteDuty(dutyId);
        return ResponseEntity.ok(JsonResult.success());
    }

    @ApiOperation(value = "值班切换状态", tags = {"值班管理"})
    @ApiResponses(value = @ApiResponse(code = 200, message = "成功", response = void.class))
    @PostMapping(value = "/duty/status/{dutyId}")
    public ResponseEntity<JsonResult> companyStatus(@PathVariable("dutyId") String dutyId) {
        dutyService.statusDuty(dutyId);
        return ResponseEntity.ok(JsonResult.success());
    }

    @ApiOperation(value = "值班日志", tags = {"值班管理"})
    @ApiResponses(value = @ApiResponse(code = 200, message = "成功", response = DutyLog.class))
    @PostMapping(value = "/duty/dutyLog")
    public ResponseEntity<JsonResult> getDutyLog(@RequestBody DutyLogSearchDto dutyLogSearchDto) {
        return ResponseEntity.ok(JsonResult.success(dutyService.getDutyLog(dutyLogSearchDto)));

    }

}
